package com.csc.banking.dao;

import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;

import com.csc.banking.model.Customer;
import com.csc.banking.model.Transaction;

@Component
public class TransactionDao extends GenaricDao 
{
	@Override
	Class<?> getEntityClass() 
	{
		return Transaction.class;
	}
	
	public List<Transaction> getAllTransactions() 
	{
    	TypedQuery<Transaction> query = em.createQuery(
            "SELECT g FROM Transaction g ORDER BY g.transactionId", Transaction.class);
    	return query.getResultList();
    }
	public List<Transaction> getAllTransactionsByCustomer(Customer customer) 
	{		
		TypedQuery<Transaction> query = em.createQuery(
            "SELECT g FROM Transaction g WHERE g.customer=:customer ORDER BY g.endTime DESC", Transaction.class).setParameter("customer", customer);
    	return query.getResultList();
    }
}
